package org.emet.service.storage;

import java.util.List;

import org.apache.log4j.Logger;
import org.emet.dao.storage.RetailReportDao;
import org.emet.jee.BusinessException;
import org.emet.jee.core.dao.arch.ArchDataSourceBaseDao;
import org.emet.jee.core.dao.arch.DataSourceModel;
import org.emet.service.dto.storage.RetailReportGroupDateEntry;
import org.emet.service.dto.storage.RetailReportItemGroupEntry;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.flex.remoting.RemotingDestination;
import org.springframework.jdbc.core.simple.SimpleJdbcTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service
@Transactional
@RemotingDestination
public class RetailReportManager {
	private Logger logger = Logger.getLogger(RetailReportManager.class);

	@Autowired
	private RetailReportDao retailReportDao;

	public void init() {
		DataSourceModel defaultDataSourceModel = ArchDataSourceBaseDao.getDefaultDataSourceModel();
		SimpleJdbcTemplate jdbcTemplate = new SimpleJdbcTemplate(defaultDataSourceModel.getDataSource());
		retailReportDao.setJdbcTemplate(jdbcTemplate);
	}

	@Transactional(readOnly = true)
	public List<RetailReportItemGroupEntry> getReportGroupByItem(java.sql.Date start, java.sql.Date end)
			throws BusinessException {
		init();
		return retailReportDao.getReportGroupByItem(start, end);
	}

	@Transactional(readOnly = true)
	public List<RetailReportGroupDateEntry> getSummarizeReportByDay(java.sql.Date start, java.sql.Date end)
			throws BusinessException {
		init();
		return retailReportDao.queryGroupByDay(start, end);
	}

	@Transactional(readOnly = true)
	public List<RetailReportGroupDateEntry> getSummarizeReportByMonth(int startYear, int startMonth, int endYear,
			int endMonth) throws BusinessException {
		init();
		return retailReportDao.queryGroupByMonth(startYear, startMonth, endYear, endMonth);
	}

	@Transactional(readOnly = true)
	public List<RetailReportGroupDateEntry> getSummarizeReportByYear(int startYear, int endYear)
			throws BusinessException {
		init();
		return retailReportDao.queryGroupByYear(startYear, endYear);
	}

}
